﻿using System;
using NUnit.Framework;
using NUnit.Framework.Constraints;
using NUnit.Framework.SyntaxHelpers;
using Yaml.Presentation.Parsing;
using Yaml.Presentation.Tokens;

namespace Yaml.Tests.Presentation.ScannerTests {
    [TestFixture]
    public class AnchorsAndAliases {
        [Test]
        public void SimpleAlias() {
            Scanner s = Helper.CreateScanner("*anchor1");
            Token t = s.GetToken();
            Assert.That(t.ToString(), Is.EqualTo("#<StreamStartToken encoding='utf-8' start={0:0,0} end={0:0,0}>"));
            t = s.GetToken();
            Assert.That(t.ToString(), Is.EqualTo("#<AliasToken anchor='anchor1' start={0:0,0} end={8:0,8}>"));
            t = s.GetToken();
            Assert.That(t.ToString(), Is.EqualTo("#<StreamEndToken start={8:0,8} end={8:0,8}>"));
        }

        [Test]
        public void SimpleAnchor() {
            Scanner s = Helper.CreateScanner("&anchor1");
            Token t = s.GetToken();
            Assert.That(t.ToString(), Is.EqualTo("#<StreamStartToken encoding='utf-8' start={0:0,0} end={0:0,0}>"));
            t = s.GetToken();
            Assert.That(t.ToString(), Is.EqualTo("#<AnchorToken anchor='anchor1' start={0:0,0} end={8:0,8}>"));
            t = s.GetToken();
            Assert.That(t.ToString(), Is.EqualTo("#<StreamEndToken start={8:0,8} end={8:0,8}>"));
        }

        [Test, ExpectedException(typeof(Yaml.Presentation.ScannerException))]
        public void InvalidAlias() {
            Scanner s = Helper.CreateScanner("* ");
            Token t = s.GetToken();
            Assert.That(t.ToString(), Is.EqualTo("#<StreamStartToken encoding='utf-8' start={0:0,0} end={0:0,0}>"));
            t = s.GetToken();
        }

        [Test, ExpectedException(typeof(Yaml.Presentation.ScannerException))]
        public void InvalidAnchor() {
            Scanner s = Helper.CreateScanner("& ");
            Token t = s.GetToken();
            Assert.That(t.ToString(), Is.EqualTo("#<StreamStartToken encoding='utf-8' start={0:0,0} end={0:0,0}>"));
            t = s.GetToken();
        }
    }
}
